package sword2offer;

/**
 * <p>
 * 替换空格
 * </p>
 * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 * @author LovelyBigDuck
 * @date 2022/3/15 20:17
 */
public class S_05 {
    class Solution {
        public String replaceSpace(String s) {
            StringBuilder stringBuilder = new StringBuilder();
            for (char c:s.toCharArray()){
                if(c==' '){
                    stringBuilder.append("%20");
                }else{
                    stringBuilder.append(c);
                }
            }
            return stringBuilder.toString();
        }
    }
}
